
#if 1 // thread leak(线程未回收)

#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

void func(void* argv)
{
    printf("hello world\r\n");
}

int main(void)
{
    pthread_t th;
    pthread_create(&th, NULL, (void*)&func, NULL);
    // pthread_join(th, NULL); // 忘记回收线程
    return 0;
}

#elif 0 // data race(数据竞争)

#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

static int gInt = 0;

void func(void* argv)
{
    gInt = 1;
    usleep(1000);
    gInt = 3;
    usleep(1000);
    gInt = 5;
}

int main(void)
{
    pthread_t th;
    pthread_create(&th, NULL, (void*)&func, NULL);

    gInt = 2;
    usleep(1000);
    gInt = 4;
    usleep(1000);
    gInt = 6;

    pthread_join(th, NULL);
    printf("gint = %d \r\n", gInt);
    return 0;
}

#endif
